package com.master.jdkproxy.methodB;


import org.junit.Test;

/**
 * 动态代理测试类
 *
 * @author zyb
 * @since 2012-8-9
 */
public class ProxyTest {

  @Test
  public void testProxy() throws Throwable {
    System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");
    // 实例化目标对象
    UserService userService = new UserServiceImpl();

    // 实例化InvocationHandler
    UserInvocationHandler invocationHandler = new UserInvocationHandler(userService);

    // 根据目标对象生成代理对象
    UserService proxy = (UserService) invocationHandler.getProxy();

    // 调用代理对象的方法
    proxy.add();
    proxy.minus();
  }

  @Test
  public void testInterfaces(){
    UserService userService = new UserServiceImpl();
    Class<?>[] clazz = userService.getClass().getInterfaces();
    for(int i =0;i<clazz.length;i++){
      System.out.println(clazz[i].getName());
    }
  }
}  